#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
自动复制MediaPipe资源文件的脚本
"""

import os
import sys
import shutil
from pathlib import Path

def copy_mediapipe_resources():
    """复制MediaPipe资源文件到打包目录"""
    try:
        import mediapipe as mp
        # 获取MediaPipe安装路径
        mp_path = Path(mp.__file__).parent
        print(f"MediaPipe路径: {mp_path}")
        
        # 目标路径
        target_base = Path("dist/面部表情分析系统/_internal/mediapipe")
        target_base.mkdir(parents=True, exist_ok=True)
        
        # 需要复制的目录
        source_dirs = ["modules", "assets"]
        
        for dir_name in source_dirs:
            source_path = mp_path / dir_name
            if source_path.exists():
                target_path = target_base / dir_name
                print(f"复制 {source_path} 到 {target_path}")
                if target_path.exists():
                    shutil.rmtree(target_path)
                shutil.copytree(source_path, target_path)
                print(f"✓ {dir_name} 复制完成")
            else:
                print(f"- {dir_name} 不存在，跳过")
        
        print("\n🎉 MediaPipe资源文件复制完成！")
        return True
    except Exception as e:
        print(f"❌ 复制过程中出错: {e}")
        return False

if __name__ == "__main__":
    copy_mediapipe_resources()
